package com.ddwl.goods.controller;

import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.ItemService;
import com.ddwl.goods.service.SkuService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ItemListApiBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.ItemApiVo;
import com.ddwl.schema.vo.goods.SkuVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品openAPI
 *
 * @author wenbin
 * @Date :2020-08-12
 */
@RestController
@RequestMapping("/ddwlOpenApi")
public class ItemOpenApiController extends BaseController {

    @Autowired
    private SkuService skuService;
    @Autowired
    private ItemService itemService;

    @PostMapping("/itemlist")
    @ApiOperation("分页查询子商品")
    public RestVo<PageVo<SkuVo>> index(@RequestBody PageBo<ItemListApiBo> pageBo) {
        return RestVo.ok(skuService.indexApi(pageBo));
    }

    @PostMapping("/mainItemlist")
    @ApiOperation("分页查询主商品")
    public RestVo<PageVo<ItemApiVo>> mainItemlist(@RequestBody PageBo<ItemListApiBo> pageBo) {
        return RestVo.ok(itemService.mainItemApilist(pageBo));
    }

    @PostMapping("/updateRealStock")
    @ApiOperation("同步库存数量")
    public RestVo updateRealStock(@RequestBody PageBo<ItemListApiBo> bo) {
        skuService.updateRealStock(bo.getParam());
        return RestVo.ok();
    }

}
